package com.example.framework.common.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.msgpack.jackson.dataformat.MessagePackFactory;

public class MsgPackUtils {

    private static final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());

    @SneakyThrows
    public static byte[] serialize(Object msgBody) {
        return objectMapper.writeValueAsBytes(msgBody);
    }

    @SneakyThrows
    public static <T> T deserialize(byte[] bytes, Class<T> resultType) {
        return objectMapper.readValue(bytes, resultType);
    }
}
